package com.link2room.rodimus.util;

import com.link2room.common.enums.BaseSysExceptionEnum;
import com.link2room.common.exception.SysException;
import com.link2room.common.util.L2RAssert;
import com.link2room.rodimus.dto.result.base.InvoiceDetailDto;

/**
 * Created by sss on 2017/9/6.
 */
public class InvoiceUtil {

    public static void checkInvoice(InvoiceDetailDto invoiceDetailDto){
        L2RAssert.isTrue(invoiceDetailDto == null,new SysException(BaseSysExceptionEnum.INVALID_PARA, "[invoiceDetailDto] is err"));
        L2RAssert.numberNull(invoiceDetailDto.getInvoiceType(), "[invoiceType] is null.");
        L2RAssert.numberNull(invoiceDetailDto.getInvoiceTitleType(), "[invoiceTitleType] is null.");
        L2RAssert.numberNull(invoiceDetailDto.getPostType(), "[postType] is null.");
        L2RAssert.stringBlank(invoiceDetailDto.getInvoiceTitle(), "[invoiceTitle] is null.");
        L2RAssert.numberNull(invoiceDetailDto.getEarlyPrepare(), "[earlyPrepare] is null.");
        if(invoiceDetailDto.getInvoiceTitleType().equals(2)){
            L2RAssert.stringBlank(invoiceDetailDto.getTaxpayerId(),"[taxpayerId] is null.");
            if(invoiceDetailDto.getInvoiceType().equals(2)){
                L2RAssert.stringBlank(invoiceDetailDto.getBankName(),"[bankName] is null.");
                L2RAssert.stringBlank(invoiceDetailDto.getBankAccount(),"[bankAccount] is null.");
            }
        }
        if(invoiceDetailDto.getEarlyPrepare().equals(1)){
            if(invoiceDetailDto.getWantTime()==null){
                throw new SysException(BaseSysExceptionEnum.INVALID_PARA, "[wantTime] is null");
            }
        }
        if(invoiceDetailDto.getPostType().equals(1)){
            L2RAssert.stringBlank(invoiceDetailDto.getReceiverName(), "[receiverName] is null.");
            L2RAssert.stringBlank(invoiceDetailDto.getReceiverMobile(), "[receiverMobile] is null.");
            L2RAssert.stringBlank(invoiceDetailDto.getReceiverAddress(), "[receiverAddress] is null.");

        }
    }
}
